package cn.stylefeng.guns.modular.kh.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.kh.entity.KhOrderOutItem;
import cn.stylefeng.guns.modular.kh.mapper.KhOrderOutItemMapper;
import cn.stylefeng.guns.modular.kh.model.params.KhOrderOutItemParam;
import cn.stylefeng.guns.modular.kh.model.result.KhOrderOutItemResult;
import  cn.stylefeng.guns.modular.kh.service.KhOrderOutItemService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 可好提总单明细 服务实现类
 * </p>
 *
 * @author zzh
 * @since 2025-10-21
 */
@Service
public class KhOrderOutItemServiceImpl extends ServiceImpl<KhOrderOutItemMapper, KhOrderOutItem> implements KhOrderOutItemService {

    @Override
    public void add(KhOrderOutItemParam param){
        KhOrderOutItem entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(KhOrderOutItemParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(KhOrderOutItemParam param){
        KhOrderOutItem oldEntity = getOldEntity(param);
        KhOrderOutItem newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public KhOrderOutItemResult findBySpec(KhOrderOutItemParam param){
        return null;
    }

    @Override
    public List<KhOrderOutItemResult> findListBySpec(KhOrderOutItemParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(KhOrderOutItemParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<KhOrderOutItemResult> getGoodsSum(List<String> orderOutNumber) {
        return this.baseMapper.getGoodsSum(orderOutNumber);
    }

    private Serializable getKey(KhOrderOutItemParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private KhOrderOutItem getOldEntity(KhOrderOutItemParam param) {
        return this.getById(getKey(param));
    }

    private KhOrderOutItem getEntity(KhOrderOutItemParam param) {
        KhOrderOutItem entity = new KhOrderOutItem();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
